package com.haotunet.app.goldtreasure.net;

import android.app.Activity;
import android.os.AsyncTask;

import com.haotunet.app.goldtreasure.R;
import com.haotunet.app.goldtreasure.model.BankModel;
import com.haotunet.app.goldtreasure.model.BannerModel;
import com.haotunet.app.goldtreasure.model.BaseModel;
import com.haotunet.app.goldtreasure.model.BuyConfirmModel;
import com.haotunet.app.goldtreasure.model.BuyGoldDetail;
import com.haotunet.app.goldtreasure.model.BuyRecordModel;
import com.haotunet.app.goldtreasure.model.CardModel;
import com.haotunet.app.goldtreasure.model.CoinModel;
import com.haotunet.app.goldtreasure.model.CouponModel;
import com.haotunet.app.goldtreasure.model.DepositOrder;
import com.haotunet.app.goldtreasure.model.DepositRecordDetailModel;
import com.haotunet.app.goldtreasure.model.DepositRecordModel;
import com.haotunet.app.goldtreasure.model.DepositReseverModel;
import com.haotunet.app.goldtreasure.model.ExchangePageInfo;
import com.haotunet.app.goldtreasure.model.ExchangeRecordDetailModel;
import com.haotunet.app.goldtreasure.model.ExchangeRecordModel;
import com.haotunet.app.goldtreasure.model.ExtractGold;
import com.haotunet.app.goldtreasure.model.GoldInfo;
import com.haotunet.app.goldtreasure.model.HomePageModel;
import com.haotunet.app.goldtreasure.model.ManageGold;
import com.haotunet.app.goldtreasure.model.MediaModel;
import com.haotunet.app.goldtreasure.model.MsgInfo;
import com.haotunet.app.goldtreasure.model.OrderInfo;
import com.haotunet.app.goldtreasure.model.PersonalInfo;
import com.haotunet.app.goldtreasure.model.PickRecordDetailModel;
import com.haotunet.app.goldtreasure.model.PickRecordModel;
import com.haotunet.app.goldtreasure.model.ProfitModel;
import com.haotunet.app.goldtreasure.model.RecommendProductModel;
import com.haotunet.app.goldtreasure.model.RedPacketDetailModel;
import com.haotunet.app.goldtreasure.model.RegularProfitModel;
import com.haotunet.app.goldtreasure.model.SellPageInfo;
import com.haotunet.app.goldtreasure.model.SellRecordModel;
import com.haotunet.app.goldtreasure.model.SignModel;
import com.haotunet.app.goldtreasure.model.StoreInfo;
import com.haotunet.app.goldtreasure.model.StoreModel;
import com.haotunet.app.goldtreasure.model.TipsInfo;
import com.haotunet.app.goldtreasure.model.UserInfo;
import com.haotunet.app.goldtreasure.model.VaultInfo;
import com.haotunet.app.goldtreasure.model.VaultRecordModel;
import com.haotunet.app.goldtreasure.model.VersionModel;
import com.haotunet.app.goldtreasure.model.WalletDetailModel;
import com.haotunet.app.goldtreasure.model.WalletInfo;
import com.haotunet.app.goldtreasure.model.WithDrawRecordModel;
import com.haotunet.app.goldtreasure.other.Interface.OnPassBackListener;
import com.haotunet.app.goldtreasure.views.MyProgressDialog;

import java.util.List;

public class ActionUtil {
    @SuppressWarnings("rawtypes")
    private AsyncTask task;
    private Activity mcontext;
    protected MyProgressDialog dialog;
    private OnPassBackListener passBack;

    public ActionUtil(Activity context) {
        mcontext = context;
        dialog = new MyProgressDialog(context, R.style.loading_dialog_style);
    }

    public void clear() {

        if (task != null) {
            task.cancel(true);
        }
    }

    public void setOnPassBackListener(OnPassBackListener passBack) {
        this.passBack = passBack;
    }

    public void getCurrentGoldPrice() {
        task = new AsyncTask<Void, Void, GoldInfo>() {
            @Override
            protected GoldInfo doInBackground(Void... params) {
                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getCurrentGoldPrice();
                return ParserUtil.parserCurrentGoldPrice(jsonStr);

            }

            protected void onPostExecute(GoldInfo result) {
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }
        }.execute();

    }

    public void getManageGoldTotalQuantity() {
        task = new AsyncTask<Void, Void, ManageGold>() {
            @Override
            protected ManageGold doInBackground(Void... params) {
                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getManageGoldTotalQuantity();
                return ParserUtil.parserManageGoldTotalQuantity(jsonStr);

            }

            protected void onPostExecute(ManageGold result) {
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }
        }.execute();

    }

    public void getBuyGoldDetail(final String productId) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BuyGoldDetail>() {
            @Override
            protected BuyGoldDetail doInBackground(Void... params) {
                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getBuyGoldDetail(productId);
                return ParserUtil.parserGetGoldDetail(jsonStr);
            }

            protected void onPostExecute(BuyGoldDetail result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }
        }.execute();

    }

    public void getRecommendProduct() {
        task = new AsyncTask<Void, Void, RecommendProductModel>() {
            @Override
            protected RecommendProductModel doInBackground(Void... params) {
                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getRecommendProduct();
                return ParserUtil.parserRecommendProduct(jsonStr);

            }

            protected void onPostExecute(RecommendProductModel result) {
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }
        }.execute();

    }

    public void getBannerData(final int type) {
        task = new AsyncTask<Void, Void, BannerModel>() {
            @Override
            protected BannerModel doInBackground(Void... params) {
                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getBanner(type);
                return ParserUtil.parserBanner(jsonStr);

            }

            protected void onPostExecute(BannerModel result) {
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }
        }.execute();

    }

    public void searchOrderState(final String orderNo, final String payGate, final String subGate) {
        task = new AsyncTask<Void, Void, BaseModel>() {
            @Override
            protected BaseModel doInBackground(Void... params) {
                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.searchOrderState(orderNo, payGate, subGate);
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }
        }.execute();

    }

    public void checkVersion(final String name, final int versionCode, final String versionName) {
        task = new AsyncTask<Void, Void, VersionModel>() {
            @Override
            protected VersionModel doInBackground(Void... params) {
                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.checkVersion(name, versionCode, versionName);
                return ParserUtil.parserCheckVersion(jsonStr);

            }

            protected void onPostExecute(VersionModel result) {
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }
        }.execute();

    }

    public void CheckLoginInfo(final String blackBox, final String username, final String password, final String clientId, final String imei) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, UserInfo>() {
            @Override
            protected UserInfo doInBackground(Void... params) {
                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.CheckLoginInfo(blackBox, username, password, clientId, imei);
                return ParserUtil.parserCheckLogin(jsonStr);

            }

            protected void onPostExecute(UserInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }
        }.execute();

    }

    private void showLoadingDialog() {
        if (mcontext==null|| mcontext.isFinishing()) {
            return;
        }
        dialog.show();
    }

    public void getRegisterCode(final String phoneNum, final String blackBox, final String imei) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getRegisterCode(phoneNum, blackBox, imei);
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void logOut() {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.logOut();
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    private void dismissLoadingDialog() {
        if (mcontext == null ||mcontext.isFinishing()) {
            return;
        }
        dialog.dismiss();
    }

    public void AddRegisterInfo(final String channelId, final String blackBox, final String phone, final String vericode, final String password,
                                final String recommendNum, final String imei, final String cliendId) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, UserInfo>() {

            @Override
            protected UserInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.submitRegisterinfo(channelId, blackBox, phone, vericode, password, recommendNum, imei, cliendId);
                return ParserUtil.parserAddRegisterInfo(jsonStr);
            }

            protected void onPostExecute(UserInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getFindPwdCode(final String phoneNum, final String blackBox, final String imei, final int type) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getFindPwdCode(phoneNum, blackBox, imei, type);
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void getWeChatCode(final String phoneNum, final String blackBox, final String imei) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getWeChatCode(phoneNum, blackBox, imei);
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void checkVeriCode(final String phoneNum, final String vericode) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.checkVeriCode(phoneNum, vericode);
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }


    public void resetNewPwd(final String blackBox, final int type, final String phone, final String code, final String oldPwd,
                            final String newPwd, final String imei, final String cliendId) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, UserInfo>() {

            @Override
            protected UserInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.resetNewPwd(blackBox, type, phone, code, oldPwd, newPwd, imei, cliendId);
                return ParserUtil.parserCheckLogin(jsonStr);
            }

            protected void onPostExecute(UserInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getHomePageInfo() {
        task = new AsyncTask<Void, Void, HomePageModel>() {

            @Override
            protected HomePageModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getHomePageInfo();
                return ParserUtil.parserGetHomePageInfo(jsonStr);
            }

            protected void onPostExecute(HomePageModel result) {
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getSellGoldPageInfo() {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, SellPageInfo>() {

            @Override
            protected SellPageInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getSellPageInfo();
                return ParserUtil.parserGetSellPageInfo(jsonStr);
            }

            protected void onPostExecute(SellPageInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getProductInfo() {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, RecommendProductModel>() {

            @Override
            protected RecommendProductModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getProductInfo();
                return ParserUtil.parserGetProductListInfo(jsonStr);
            }

            protected void onPostExecute(RecommendProductModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getGoldCoinInfo(final String pageNum) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, CoinModel>() {

            @Override
            protected CoinModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getGoldCoinInfo(pageNum);
                return ParserUtil.parserGetGoldCoinInfo(jsonStr);
            }

            protected void onPostExecute(CoinModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getRedPacketDetail(final String pageNum) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, RedPacketDetailModel>() {

            @Override
            protected RedPacketDetailModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getRedPacketDetail(pageNum);
                return ParserUtil.parserGetRedPacketDetail(jsonStr);
            }

            protected void onPostExecute(RedPacketDetailModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getDiscoverNews(final int type, final String pageNum) {

        task = new AsyncTask<Void, Void, MediaModel>() {

            @Override
            protected MediaModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getDiscoverNews(type, pageNum);
                return ParserUtil.parserGetDiscoverNews(jsonStr);
            }

            protected void onPostExecute(MediaModel result) {

                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }


    public void getSellGoldRecord(final String pageNum) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, SellRecordModel>() {

            @Override
            protected SellRecordModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getSellGoldRecord(pageNum);
                return ParserUtil.parserGetSellRecord(jsonStr);
            }

            protected void onPostExecute(SellRecordModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getDepositGoldRecord(final String pageNum) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, DepositRecordModel>() {

            @Override
            protected DepositRecordModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getDepositGoldRecord(pageNum);
                return ParserUtil.parserGetDepositRecord(jsonStr);
            }

            protected void onPostExecute(DepositRecordModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getExtractGoldRecord(final String pageNum) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, PickRecordModel>() {

            @Override
            protected PickRecordModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getExtractGoldRecord(pageNum);
                return ParserUtil.parserGetExtractRecord(jsonStr);
            }

            protected void onPostExecute(PickRecordModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getMyBuyRecord(final int type, final String pageNum) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BuyRecordModel>() {

            @Override
            protected BuyRecordModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getMyRegularBuyRecord(type, pageNum);
                return ParserUtil.parserGetCurrentBuyRecord(jsonStr);
            }

            protected void onPostExecute(BuyRecordModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void sellGoldOperation(final String goldPrice, final String goldGram) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, OrderInfo>() {

            @Override
            protected OrderInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.sellGoldOperation(goldPrice, goldGram);
                return ParserUtil.parserMakeOrderOperation(jsonStr);
            }

            protected void onPostExecute(OrderInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void submitSellGoldData(final String blackBox, final String orderNo, final String payPassword) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.submitSellGoldData(blackBox, orderNo, payPassword);
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }


    public void getMyCoupons(final int type, final String pageNum) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, CouponModel>() {

            @Override
            protected CouponModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getMyCoupons(type, pageNum);
                return ParserUtil.parserGetMyCoupons(jsonStr);
            }

            protected void onPostExecute(CouponModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getMyCurrentGold(final String productId) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, GoldInfo>() {

            @Override
            protected GoldInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getMyCurrentGoldInfo(productId);
                return ParserUtil.parserGetMyCurrentGold(jsonStr);
            }

            protected void onPostExecute(GoldInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void currentToRegular(final String goldGrams, final String regularId, final String tradePwd) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.currentToRegular(goldGrams, regularId, tradePwd);
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getAllShopPositionInfo(final int type) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, DepositReseverModel>() {

            @Override
            protected DepositReseverModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getAllShopPositionInfo(type);
                return ParserUtil.parserGetAllShopPositionInfo(jsonStr);
            }

            protected void onPostExecute(DepositReseverModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void submitDepositReseverInfo(final String shopId, final String bookTime) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, DepositOrder>() {

            @Override
            protected DepositOrder doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.submitDepositGoldReseverInfo(shopId, bookTime);
                return ParserUtil.getDepositReseverOrder(jsonStr);
            }

            protected void onPostExecute(DepositOrder result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void submitExtractReseverInfo(final String shopId, final String takeTime, final String is_bill,
                                         final String goldType, final List<ExtractGold> gramList) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, OrderInfo>() {

            @Override
            protected OrderInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.submitExtractGoldReseverInfo(shopId, takeTime, is_bill, goldType, gramList);
                return ParserUtil.parserMakeOrderOperation(jsonStr);
            }

            protected void onPostExecute(OrderInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void submitExchangeReseverInfo(final String quantity, final String shopId) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, OrderInfo>() {

            @Override
            protected OrderInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.submitExchangeGoldReseverInfo(quantity, shopId);
                return ParserUtil.parserMakeOrderOperation(jsonStr);
            }

            protected void onPostExecute(OrderInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getExtractGoldType() {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, GoldInfo>() {

            @Override
            protected GoldInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getExtractGoldType();
                return ParserUtil.parserCurrentGoldPrice(jsonStr);

            }

            protected void onPostExecute(GoldInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getMyBankCardList() {
        task = new AsyncTask<Void, Void, CardModel>() {

            @Override
            protected CardModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getBankCradList();
                return ParserUtil.parserGetMyCardList(jsonStr);

            }

            protected void onPostExecute(CardModel result) {
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getTips(final int type) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, TipsInfo>() {

            @Override
            protected TipsInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getTips(type);
                return ParserUtil.parserTipsInfo(jsonStr);

            }

            protected void onPostExecute(TipsInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void submitRechargeorder(final String payment) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, OrderInfo>() {

            @Override
            protected OrderInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.submitRechargeOrder(payment);
                return ParserUtil.parserMakeOrderOperation(jsonStr);

            }

            protected void onPostExecute(OrderInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void deleteBindCard(final String card_no) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.deleteBindCard(card_no);
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void getVaultPageInfo() {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, VaultInfo>() {

            @Override
            protected VaultInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getVaultPageInfo();
                return ParserUtil.parserGetVaultPageInfo(jsonStr);
            }

            protected void onPostExecute(VaultInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void getWalletDetail(final String pageNum) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, WalletDetailModel>() {

            @Override
            protected WalletDetailModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getWalletDetail(pageNum);
                return ParserUtil.parserGetWalletDetail(jsonStr);
            }

            protected void onPostExecute(WalletDetailModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void getPersonalPageInfo() {
        task = new AsyncTask<Void, Void, PersonalInfo>() {

            @Override
            protected PersonalInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getPersonalPageInfo();
                return ParserUtil.parserGetPersonalPageInfo(jsonStr);
            }

            protected void onPostExecute(PersonalInfo result) {
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void everyday_sign() {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, SignModel>() {

            @Override
            protected SignModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.everyday_sign();
                return ParserUtil.parserGetEverydaySign(jsonStr);
            }

            protected void onPostExecute(SignModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void getMyProfit() {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, ProfitModel>() {

            @Override
            protected ProfitModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getMyProfit();
                return ParserUtil.parserGetMyProfit(jsonStr);
            }

            protected void onPostExecute(ProfitModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void getWithdrawRecord(final String pageNum) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, WithDrawRecordModel>() {

            @Override
            protected WithDrawRecordModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getWithdrawRecordList(pageNum);
                return ParserUtil.parserGetWithdrawRecord(jsonStr);
            }

            protected void onPostExecute(WithDrawRecordModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

     public void submitFeedBack(final String content) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.submitFeedback(content);
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }


    public void confirmChoose(final String regularId, final String goldGrams, final String orderPrice,
                              final String purchaseType) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BuyConfirmModel>() {

            @Override
            protected BuyConfirmModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.confirmChoose(regularId, goldGrams, orderPrice, purchaseType);
                return ParserUtil.parserConfirmChoose(jsonStr);
            }

            protected void onPostExecute(BuyConfirmModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void makeOrderOperation(final String quantity, final String unitPrice, final String totalPrice,
                                   final String couponIds, final String couponValue, final String isUseRedPacket, final String productId, final String purchaseType, final String imei, final String blackBox) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, OrderInfo>() {

            @Override
            protected OrderInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.makeOrderOperation(quantity, unitPrice, totalPrice, couponIds, couponValue, isUseRedPacket,
                        productId, purchaseType, imei, blackBox);
                return ParserUtil.parserMakeOrderOperation(jsonStr);
            }

            protected void onPostExecute(OrderInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void getPayCode(final String orderNo, final String realName, final String cardNo, final String idNo,
                           final String mobile, final String orderAmount, final String payGate, final String subGate) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getPayCode(orderNo, realName, cardNo, idNo, mobile, orderAmount, payGate, subGate);
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void submitPayInfo(final String cardNo, final String orderNo, final String code, final String payGate, final String subGate) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.submitPayInfo(cardNo, orderNo, code, payGate, subGate);
                return ParserUtil.parserGetRegisterCode(jsonStr);

            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getRegularProfitRecord(final int type, final String pageNum) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, RegularProfitModel>() {

            @Override
            protected RegularProfitModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getRegularProfitList(type, pageNum);
                return ParserUtil.parserGetRegularProfitRecord(jsonStr);

            }

            protected void onPostExecute(RegularProfitModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void setTradingPwd(final String pwd) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.setTradingPwd(pwd);
                return ParserUtil.parserGetRegisterCode(jsonStr);

            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getStoreList(final int pageNum, final double lon, final double lat, final String address,
                             final int type) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, StoreModel>() {

            @Override
            protected StoreModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getStoreList(pageNum, lon, lat, address, type);
                return ParserUtil.parserGetStoreList(jsonStr);
            }

            protected void onPostExecute(StoreModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getWalletPageInfo() {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, WalletInfo>() {

            @Override
            protected WalletInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getWalletPageInfo();
                return ParserUtil.parserGetWalletPageInfo(jsonStr);
            }

            protected void onPostExecute(WalletInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void getStoreDetailInfo(final String shopId) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, StoreInfo>() {

            @Override
            protected StoreInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getStoreDetailInfo(shopId);
                return ParserUtil.parserGetStoreDetailInfo(jsonStr);
            }

            protected void onPostExecute(StoreInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void getVaultRecordInfo(final String pageNum) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, VaultRecordModel>() {

            @Override
            protected VaultRecordModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getVaultDetailInfo(pageNum);
                return ParserUtil.parserGetVaultRecordInfo(jsonStr);
            }

            protected void onPostExecute(VaultRecordModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void verifyWithdrawFee(final String money) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.verifyWithdrawFee(money);
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void submitWithdrawsApply(final String cardNum, final String amount, final String payPassword,
                                     final String address) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.submitWithdrawsApply(cardNum, amount, payPassword, address);
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void submitAnthInfo(final String realname, final String idcard) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.submitAuthInfo(realname, idcard);
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void getPickRecordDetail(final String orderNo) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, PickRecordDetailModel>() {

            @Override
            protected PickRecordDetailModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getPickRecordDetail(orderNo);
                return ParserUtil.parserGetPickRecordDetail(jsonStr);
            }

            protected void onPostExecute(PickRecordDetailModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void cancleExchangeOrder(final String exchangeNo) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.cancleExchangeOrder(exchangeNo);
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void cancleDepositOrder(final String orderNo) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.cancleDepositOrder(orderNo);
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void checkChangeTradingPwdInfo(final String code, final String idNum) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.checkChangeTradingPwdInfo(code, idNum);
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void submitBalancePayInfo(final String password, final String amount, final String orderNo) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BaseModel>() {

            @Override
            protected BaseModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.submitBalancePayInfo(password, amount, orderNo);
                return ParserUtil.parserGetRegisterCode(jsonStr);
            }

            protected void onPostExecute(BaseModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void getDepositRecordDetail(final String orderNo) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, DepositRecordDetailModel>() {

            @Override
            protected DepositRecordDetailModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getDepositRecordDetail(orderNo);
                return ParserUtil.parserGetDepositRecordDetail(jsonStr);
            }

            protected void onPostExecute(DepositRecordDetailModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void getExchangeRecordDetail(final String exchangeNo) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, ExchangeRecordDetailModel>() {

            @Override
            protected ExchangeRecordDetailModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getExchangeRecordDetail(exchangeNo);
                return ParserUtil.parserGetExchangeRecordDetail(jsonStr);
            }

            protected void onPostExecute(ExchangeRecordDetailModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void getExchangeRecord(final String pageNum) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, ExchangeRecordModel>() {

            @Override
            protected ExchangeRecordModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getExchangeGoldRecord(pageNum);
                return ParserUtil.parserGetExchangeRecord(jsonStr);
            }

            protected void onPostExecute(ExchangeRecordModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void getExchangePageInfo() {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, ExchangePageInfo>() {

            @Override
            protected ExchangePageInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getExchangePageInfo();
                return ParserUtil.parserGetExchangePageInfo(jsonStr);
            }

            protected void onPostExecute(ExchangePageInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void getMyTotalGold() {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, GoldInfo>() {

            @Override
            protected GoldInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getMyTotalGold();
                return ParserUtil.parserGetMyTotalGold(jsonStr);
            }

            protected void onPostExecute(GoldInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();

    }

    public void getUnReadMsg() {
        task = new AsyncTask<Void, Void, MsgInfo>() {

            @Override
            protected MsgInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getUnReadMsg();
                return ParserUtil.parserMsgInfo(jsonStr);
            }

            protected void onPostExecute(MsgInfo result) {
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void checkIsBindWechat() {
        task = new AsyncTask<Void, Void, UserInfo>() {

            @Override
            protected UserInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.checkIsBindWechat();
                return ParserUtil.parserCheckLogin(jsonStr);
            }

            protected void onPostExecute(UserInfo result) {
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void wechatAuth(final String weChatCode, final String cliendId, final String imei, final String blackBox, final String channelId) {
        dialog.show();
        task = new AsyncTask<Void, Void, UserInfo>() {

            @Override
            protected UserInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.wechatAuth(weChatCode, cliendId, imei, blackBox, channelId);
                return ParserUtil.parserCheckLogin(jsonStr);
            }

            protected void onPostExecute(UserInfo result) {
                dialog.dismiss();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void wechatLogin(final String weChatCode, final String userName, final String cliendId, final String imei, final String code, final String blackBox, final String channelId) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, UserInfo>() {

            @Override
            protected UserInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.wechatLogin(weChatCode, userName, cliendId, imei, code, blackBox, channelId);
                return ParserUtil.parserCheckLogin(jsonStr);
            }

            protected void onPostExecute(UserInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void wechatRegister(final String weChatCode, final String userName, final String password, final String cliendId, final String imei, final String blackBox, final String channelId) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, UserInfo>() {

            @Override
            protected UserInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.wechatRegister(weChatCode, userName, password, cliendId, imei, blackBox, channelId);
                return ParserUtil.parserCheckLogin(jsonStr);
            }

            protected void onPostExecute(UserInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void bindWechat(final String weChatCode) {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, UserInfo>() {

            @Override
            protected UserInfo doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.bindWechat(weChatCode);
                return ParserUtil.parserCheckLogin(jsonStr);
            }

            protected void onPostExecute(UserInfo result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }

    public void getSupportBankList() {
        showLoadingDialog();
        task = new AsyncTask<Void, Void, BankModel>() {

            @Override
            protected BankModel doInBackground(Void... params) {

                DataUtil data = DataUtil.getInstance(mcontext);
                String jsonStr = data.getSupportBankList();
                return ParserUtil.getSupportBankList(jsonStr);
            }

            protected void onPostExecute(BankModel result) {
                dismissLoadingDialog();
                if (passBack != null) {
                    passBack.passBack(result);
                }
            }

        }.execute();
    }
}
